unit FullScreenAppDetect;

interface

function IsFullScrAppActive: Boolean;
function GetAppTitle: String;
function GetAppExeName: String;

implementation

uses
 Forms,
 Windows,
 SysUtils,
 Tlhelp32;

function IsFullScrAppActive: Boolean;
 var
  p, q: TPoint;
begin
 //bottom-right point
 p.X:=Screen.Width-1;
 p.Y:=Screen.Height-1;
 //upper-left point
 q.X:=1;
 q.Y:=1;
 //fullscreen detect
 Result:= WindowFromPoint(p) = WindowFromPoint(q);
end;

function GetControlText(hDlg: HWND): String;
var
  dlg_text: array[0..255] of Char;
begin
 ZeroMemory(@dlg_text, SizeOf(dlg_text));
 GetWindowText(hDlg, @dlg_text, 255);
 Result := dlg_text;
end;

function GetAppTitle: String;
 var
  p: TPoint;
begin
 //bottom-right point
 p.X:=Screen.Width-1;
 p.Y:=Screen.Height-1;
 Result:=GetControlText(WindowFromPoint(p));
end;

function GetAppExeName: String;
 var
  p: TPoint;
  pProcID : ^DWORD;
  ContinueLoop   : LongBool;
  FSnapshotHandle : THandle;
  FProcessEntry32 : TProcessEntry32;
begin
 p.X:=Screen.Width-1;
 p.Y:=Screen.Height-1;
 //
 GetMem(pProcID, SizeOf (DWORD));
 GetWindowThreadProcessId (WindowFromPoint(p), pProcID);
 //
 FSnapshotHandle := CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);
 FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
 ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
 Result := '';
 while (Integer (ContinueLoop) <> 0) and (Result='') do
  begin
   if FProcessEntry32.th32ProcessID = pProcID^ then
     Result := FProcessEntry32.szExeFile;
   ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
  end;
 //
 FreeMem(pProcID);
 //
 Result:=ExtractFileName(Result);
end;

end.
